//
//  UIButton+STUIButton.m
//  OCVVeibo
//
//  Created by leergou on 16/7/21.
//  Copyright © 2016年 WhiteHouse. All rights reserved.
//

#import "UIButton+STUIButton.h"

@implementation UIButton (STUIButton)

- (instancetype)initWithTitle:(NSString *)title target:(id)target action:(SEL)action{
    
    if (self = [super init]) {
        [self setupWithTitle:title bgNorImg:nil bgHighImg:nil highlightedImg:nil normalImg:nil selectedImg:nil target:target action:action];
    }
    return self;
}

- (instancetype)initWithTitle:(NSString *)title norImg:(NSString *)norImg target:(id)target action:(SEL)action{
    
    if (self = [super init]) {
        
        [self setupWithTitle:title bgNorImg:nil bgHighImg:nil highlightedImg:nil normalImg:norImg selectedImg:nil target:target action:action];
    }
    return self;
}


- (instancetype)initWithTitle:(NSString *)title bgNorImg:(NSString *)bgNorImg target:(id)target action:(SEL)action{
    
    if (self = [super init]) {
        
        [self setupWithTitle:title bgNorImg:bgNorImg bgHighImg:nil highlightedImg:nil normalImg:nil selectedImg:nil target:target action:action];
    }
    return self;
}


- (instancetype)initWithTitle:(NSString *)title bgNorImg:(NSString *)bgNorImg bgHighImg:bgHighImg target:(id)target action:(SEL)action{
    
    if (self = [super init]) {
        
        [self setupWithTitle:title bgNorImg:bgNorImg bgHighImg:bgHighImg highlightedImg:nil normalImg:nil selectedImg:nil target:target action:action];
    }
    return self;
}

- (instancetype)initWithTitle:(NSString *)title bgNorImg:(NSString *)bgNorImg bgHighImg:(NSString *)bgHighImg highlightedImg:(NSString *)highLightedImg normalImg:(NSString *)normalImg selectedImg:(NSString *)seletedImg target:(id)target action:(SEL)action{
    
    if (self = [super init]) {
        
        [self setupWithTitle:title bgNorImg:bgNorImg bgHighImg:bgHighImg highlightedImg:highLightedImg normalImg:normalImg selectedImg:seletedImg target:target action:action];
    }
    return self;
}


- (void)setupWithTitle:(NSString *)title bgNorImg:(NSString *)bgNorImg bgHighImg:(NSString *)bgHighImg highlightedImg:(NSString *)highLightedImg normalImg:(NSString *)normalImg selectedImg:(NSString *)seletedImg target:(id)target action:(SEL)action{
    
    if (title) {
        [self setTitle:title forState:UIControlStateNormal];
    }
    if (bgNorImg) {
        [self setBackgroundImage:[UIImage imageNamed:bgNorImg] forState:UIControlStateNormal];
    }
    if (bgHighImg) {
        [self setBackgroundImage:[UIImage imageNamed:bgHighImg] forState:UIControlStateHighlighted];
    }
    if (highLightedImg) {
       [self setImage:[UIImage imageNamed:highLightedImg] forState:UIControlStateHighlighted];
    }
    if (normalImg){
        [self setImage:[UIImage imageNamed:normalImg] forState:UIControlStateNormal];
    }
    if (seletedImg){
        [self setImage:[UIImage imageNamed:seletedImg] forState:UIControlStateSelected];
    }
    if (target && action){
        [self addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    }
}


@end
